package com.zm.demo.core.concurrent;

import static java.lang.System.out;

/**
 * thread.join()时，main进入到了等待线程执行结束，
 * 而Lazy类由main方法初始化，thread又在等待main初始化完成
 * 循环等待，造成死锁
 * @author zoum
 * @create 2019/7/22 14:02
 */
public class Lazy {

    public static boolean flag = false;

    static{
        out.println(0);
        Thread thread = new Thread(() -> {
            out.println(1);
        });
        thread.start();
        try {
            thread.join();
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args){
        out.println(2);
        out.println(flag);
        out.println(3);
    }
}
